<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>新增商品</title>
		<link rel="stylesheet" href="css/bootstrap.min.css" />
		<style>
			body{
				margin-left: 50px;
				margin-top: 30px;
				width: 80%;
				background-color: lightblue;
			}
		</style>
		<script src="js/axios.min.js" type="text/javascript"></script>
		<script src="js/vue.js" type="text/javascript"></script> 
		<script src="https://cdn.bootcdn.net/ajax/libs/qs/6.9.6/qs.js"></script>	
	</head>
	<body>
		<div id="app">
			<label>
				分类:<select v-model="selectId">
					<option v-for="classify in classifyList" v-bind:value="classify.classifyId">
					 {{classify.classifyName}}
					</option>
				</select>
			</label><br>
			<label>名称：<input v-model="goodsName" /></label><br />
			<label>品牌：<input v-model="brand" /></label><br />
			<label>厂家：<input v-model="factory" /></label><br />
			<label>库存：<input v-model="stock" /></label><br />
			<label>价格：<input v-model="price" /></label><br />
			<label>备注：<input v-model="remark" /></label><br />
				<button class="btn btn-primary" v-on:click="saveGoods()">添加</button>
		</div>
	</body>
	<script>
		var config={
			el:"#app",
			data:{
				selectId:null,
			   classifyList:[],
			   goodsName:null,
			   brand:null,
			   factory:null,
			   stock:null,
			   price:null,
			   remark:null
			},
			methods:{
				findClassify:function(){
					let serverUrl="http://localhost:8088/classify/"
					let vue=this;
					axios.get(serverUrl)
					.then(function(response){
						vue.classifyList=response.data.data;
						console.log(response.data)
					})
					.catch(function(e){
						window.alert("联网失败")
						console.log(e);
					})
				},
				saveGoods:function(){
					let serverUrl=`http://localhost:8088/goods/`
					let data={
					    "goodsName": this.goodsName,
					     "classifyId": this.selectId,
					     "factory": this.factory,
					     "stock": this.stock,
					     "price": this.price,
					     "brand": this.brand,
					     "remark": this.remark,
					  }
					console.log(serverUrl);
					axios.post(serverUrl,data
					)
					.then(function(response){
						window.alert(response.data.data);
						location.href="goods.html"
					})
					.catch(function(e){
						window.alert("联网失败")
						console.log(e);
					})
				},
					
			},
			mounted:function(){
				this.findClassify();
			}
		}
		var vue =new Vue(config);
	</script>
</html>
